I'd thought that I would write about
using
Design
by Contract
preconditions and postconditions
with Perl and VB.
I had not used Perl lvalue subs before,
but I thought it would be easy to
use an lvalue sub to perform
data validation as
preconditions and postconditions.
After much experimentation, then
some Googling,
I finally found a
post
about lvalue subs on Perl Monks
explaining that you can't actually
do anything with the value
while you are in the lvalue sub:
- You can't examine the proposed new
value before the assignment; and
- You can't check the value after assigning
it.
Thus endeth the lesson for the day.
Contextual::Return
runrig on 2006-06-16T22:17:58
Contextual-Return claims to be able to accomplish this sort of validation.
Extending lvalue subs is possible
You may find the following two links interesting
http://perlmonks.org/?node_id=424644http://perlmonks.org/?node_id=369354The latter explains how to use tied variables in conjunction with lvalue subs as one way to accomplish what you are doing.
There are modules on CPAN (referenced in the links I believe) that show better ways.